<?php

class Mail
{
	public static function encode64($t) {
		return '=?UTF-8?B?'.base64_encode($t).'?=';
	}

	public static function getServerInfo() {
		$ip1 = $_SERVER['REMOTE_ADDR'];
		$ip2 = $_SERVER['HTTP_CLIENT_IP'];
		if (!$ip2) $ip2 = $_SERVER['HTTP_X_FORWARDED_FOR'];

		$host1 = gethostbyaddr($ip1);
		$host2 = gethostbyaddr($ip1);

		$agent = $_SERVER['HTTP_USER_AGENT'];

		$s = "   ip = " . $ip1;
		if ($ip2 && ($ip1!=$ip2)) $s .= " $ip2";
		if ($host1 || $host2) {
			$s .= "\n host = " . $host1;
			if ($host2 && ($host1!=$host2)) $s .= " $host2";
		}
		$s .= "\nagent = $agent";

		return "\n\n--------\n$s";
	}

	public static function sendMail($from,$to,$subj,$body) {
		$subj64 = self::encode64($subj);
		$res = @mail($to,$subj64,$body.self::getServerInfo(),
			// headers
			"From: $from\n".
			// "Reply-To: some@where.net\n".
			"Return-Path: $from\n".
			"MIME-Version: 1.0\n".
			"Content-Type: text/plain; charset=\"utf-8\"\n".
			"Content-Transfer-Encoding: 8bit");
		return $res;
	}
}

// eof
